﻿using PipeDetection.Repository;
using PipeDetection.Model;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PipeDetection.UI.管段
{
    public partial class FrmNewPipeNet : UIForm2
    {
      
        private PipeNetArea result = new PipeNetArea();
        public FrmNewPipeNet()
        {
            InitializeComponent();
        }
        private bool isedit=false;
        public FrmNewPipeNet(PipeNetArea pipeNet):this()
        {
            this.Text = "编辑管网分段信息";
            result = pipeNet;
            uiTextBox1.Text=result.PipeNetAreaName;
            uiRichTextBox1.Text=result.PipeNetAreaDescription;
            isedit = true;
        }
        private void uiButton2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            result.PipeNetAreaName = uiTextBox1.Text;
            result.PipeNetAreaDescription = uiRichTextBox1.Text;
            if (!isedit)
            {
                if (Globel.PipeNetAreaRepository.Add(result) > 0) {
                    Tag = result;
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    Console.WriteLine("插入新网段数据失败");
                    DialogResult = DialogResult.Cancel;
                }
            }
            else
            {
                Globel.PipeNetAreaRepository.Update(result);
                Tag = result;
                DialogResult = DialogResult.OK;
            }
        }
    }
}
